package com.guagua.vas.homepage.database;

import java.util.Map;

import org.apache.log4j.Logger;



import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;

public class DatabaseObjectLoader {

	static Logger logger = Logger.getLogger(DatabaseObjectLoader.class.getName());

	static interface ObjectFactory {

		public abstract Object loadObject(long id);
	}

	private static Map objectFactories = new ConcurrentHashMap();

	private DatabaseObjectLoader() {}

	public static boolean isKnownType(int type) {
		if (objectFactories.isEmpty())
			populateObjectFactories();
		return objectFactories.containsKey(new Integer(type));
	}

	public static Object getBaduObject(int objectType, long objectID) {
		if (isKnownType(objectType))
			return ((ObjectFactory) objectFactories.get(new Integer(objectType))).loadObject(objectID);
		else
			return null;
	}

	private static synchronized void populateObjectFactories() {
//		objectFactories.put(new Integer(PlayerConstants.PLAYER_CATEGORY), new ObjectFactory() {
//
//			public Object loadObject(long id) {
//				try {
//					return CategoryManagerFactory.getInstance().getCategory((int)id);
//				} catch (CategoryNotFoundException cnfe) {
//					logger.debug(cnfe);
//					return null;
//				}
//			}
//
//		});

	}


	static {
		try {
			populateObjectFactories();
		} catch (Exception e) {
			logger.error(e);
		}
	}
}